/**
 * Created by ChenJiangwei on 2017/5/2.
 */
//成交房源添加的缓存在historySearchRecord键值对里里面保存
var $recordList = historyControl.recordList;
var $searchInput=historyControl.searchInput;
var $searchBtn = historyControl.searchBtn;
var url=common.globalHost+common.dealQueryVillageByName;
//成交小区搜索是post请求
$searchBtn.off('tap').on('tap',function(e){
	var $this=$(this);
	var checkCase=$this.hasClass("act-ago");
	var searchVal=$searchInput.val();
	var sendData={
		        pageIndex:1,
		        pageSize:10,
		        villageId:searchVal
		    };
	if(!!checkCase&&searchVal.length>=2){
		$this.removeClass("act-ago");
		request({
			url:url,
			sendData:sendData
		});
		$this.addClass("act-ago");
		e.preventDefault();
        return false;
	}else{
		console.log('请稍后重试');
	}
});
function request(options){
	var url=options.url;
	var sendData=options.sendData;
	var searchVal=sendData.villageId;
	$.ajax({
		url:url,
		sendData:sendData,
		type:"POST",
		contentType: "application/json",
		dataType:"json",
		success:function(data){
			//添加缓存；
			historyControl.buildCacheHistory("historySearchRecord",searchVal);
			window.location.href="villageSearchResult.html";
		},
		timeout:10000,
		error: function (XMLHttpRequest, textStatus, errorThrown) {
            // console.log("网络不畅，请稍后重试");
            historyControl.errDialog("网络不畅，请稍后重试");
        }
	});
}
//创建搜索历史列表
historyControl.buildSearchHistory({
	dataList:common.getLocalData("historySearchRecord"),
	targetSelector:$recordList
});
//清除搜索记录
historyControl.clearSearchRecord("historySearchRecord");
//点击搜索记录回填到search-input框里
historyControl.rebackInput();
//点击li搜所
$recordList.find("li").off('tap').on('tap',function(e){
	var $this=$(this);
	var innerHtml=$this.html();
	var sendData={
		        pageIndex:1,
		        pageSize:10,
		        villageId:innerHtml
		};
		request({
			url:url,
			sendData:sendData
		});
	e.preventDefault();
    return false;
})